Skip to content

Conversation

@taljacob2
Copy link
Member

@taljacob2 taljacob2 commented Jul 26, 2025

Fixes the following error, when running `npm run dev` in the backend:

```
/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/models/user_model.ts:34:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.

34             id: ret._id,
               ~~

  src/types/user_types.ts:13:5
    13     id: string;
           ~~
    The expected type comes from property 'id' which is declared here on type 'UserData'
src/models/user_model.ts:35:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.

35             username: ret.username,
               ~~~~~~~~

  src/types/user_types.ts:14:5
    14     username: string;
           ~~~~~~~~
    The expected type comes from property 'username' which is declared here on type 'UserData'
src/models/user_model.ts:36:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.

36             email: ret.email,
               ~~~~~

  src/types/user_types.ts:15:5
    15     email: string;
           ~~~~~
    The expected type comes from property 'email' which is declared here on type 'UserData'
src/models/user_model.ts:37:13 - error TS2322: Type 'unknown' is not assignable to type 'string'.

37             password: ret.password,
               ~~~~~~~~

  src/types/user_types.ts:16:5
    16     password: string;
           ~~~~~~~~
    The expected type comes from property 'password' which is declared here on type 'UserData'
src/models/user_model.ts:38:13 - error TS2322: Type 'unknown' is not assignable to type 'string | undefined'.

38             imageFilename: ret?.imageFilename,
               ~~~~~~~~~~~~~

  src/types/user_types.ts:17:5
    17     imageFilename?: string;
           ~~~~~~~~~~~~~
    The expected type comes from property 'imageFilename' which is declared here on type 'UserData'
src/models/user_model.ts:39:13 - error TS2322: Type 'unknown' is not assignable to type 'string | undefined'.

39             createdAt: ret.createdAt,
               ~~~~~~~~~

  src/types/user_types.ts:18:5
    18     createdAt?: string,
           ~~~~~~~~~
    The expected type comes from property 'createdAt' which is declared here on type 'UserData'
src/models/user_model.ts:40:13 - error TS2322: Type 'unknown' is not assignable to type 'string | undefined'.

40             updatedAt: ret.updatedAt
               ~~~~~~~~~

  src/types/user_types.ts:19:5
    19     updatedAt?: string,
           ~~~~~~~~~
    The expected type comes from property 'updatedAt' which is declared here on type 'UserData'

    at createTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1617:30)
    at node:internal/modules/cjs/loader:1895:10
    at Object.require.extensions.<computed> [as .ts] (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
  diagnosticCodes: [
    2322, 2322,
    2322, 2322,
    2322, 2322,
    2322
  ]
}
[nodemon] app crashed - waiting for file changes before starting...
```

**Problem**
In `user_model.ts`, the `transform` function is typed
to return `UserData`, which expects all fields to be
of type `string` (or `string | undefined` for some).
However, the `ret` object passed to the transform
function is not strongly typed—it is inferred as
`any` or `unknown` by TypeScript, especially when
using strict settings.

This fixes all the models` `transform` function.

Signed-off-by: Tal Jacob <taljacob2@gmail.com>
Fixes the following error, when running the backend:

```
/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859
    return new TSError(diagnosticText, diagnosticCodes, diagnostics);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/models/user_model.ts:34:17 - error TS18046: 'ret._id' is of type 'unknown'.

34             id: ret._id.toString(),
                   ~~~~~~~
src/models/user_model.ts:39:54 - error TS2339: Property 'toISOString' does not exist on type '{}'.

39             createdAt: ret.createdAt ? ret.createdAt.toISOString() : undefined,
                                                        ~~~~~~~~~~~
src/models/user_model.ts:40:54 - error TS2339: Property 'toISOString' does not exist on type '{}'.

40             updatedAt: ret.updatedAt ? ret.updatedAt.toISOString() : undefined
                                                        ~~~~~~~~~~~

    at createTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:859:12)
    at reportTSError (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:863:19)
    at getOutput (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1077:36)
    at Object.compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1433:41)
    at Module.m._compile (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1617:30)
    at node:internal/modules/cjs/loader:1895:10
    at Object.require.extensions.<computed> [as .ts] (/home/tal/Code/NextStep/nextstep-backend/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14) {
  diagnosticCodes: [ 18046, 2339, 2339 ]
}
[nodemon] app crashed - waiting for file changes before starting...
```

This tells TypeScript that `ret` is an object with
string keys and any values, so you can safely
access properties and call methods like
`.toString()` and `.toISOString()`.

The root cause of the error is that in the
user_model.ts, the ret parameter in the
transform function is not typed,
so TypeScript infers it as unknown.
This is why you get errors like 'ret._id'
is of type 'unknown' and 'toISOString'
does not exist on type '{}'.
Other models (like posts, comments, company)
fix this by typing ret as Record<string, any>.

The fix has been applied the ret parameter
in the user_model.ts transform function
is now typed as Record<string, any>.
This will resolve the TypeScript errors about
unknown and {} types for ret._id and date fields.

Signed-off-by: Tal Jacob <taljacob2@gmail.com>
The Vite configuration has been updated to use
the `VITE_DOMAIN_NAME` environment variable for
the host in both the server and preview sections.
Now, if the `.env` file sets
`VITE_DOMAIN_NAME=0.0.0.0`, the frontend will be
exposed on all network interfaces.

Signed-off-by: Tal Jacob <taljacob2@gmail.com>
Signed-off-by: Tal Jacob <taljacob2@gmail.com>
@taljacob2 taljacob2 requested review from LiavTB and Lina0Elman July 26, 2025 18:23
@taljacob2 taljacob2 self-assigned this Jul 26, 2025
@taljacob2 taljacob2 added documentation Improvements or additions to documentation enhancement New feature or request labels Jul 26, 2025
@taljacob2 taljacob2 merged commit 517b2df into master Aug 1, 2025
6 checks passed
@taljacob2 taljacob2 deleted the NXD-32 branch August 1, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants